package com.wzh.store.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wzh.store.entity.Product;
import com.wzh.store.mapper.ProductMapper;
import com.wzh.store.service.IProductService;
import com.wzh.store.service.ex.ProductNotFindException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author wzh
 * @create 2022/4/29 14:43
 * @Description：
 */
@Service
public class ProductServiceimpl extends ServiceImpl<ProductMapper, Product> implements IProductService {
    @Autowired
    public ProductMapper productMapper;


    @Override
    public List<Product> findHostProduct() {
        List<Product> list = productMapper.findHostProducts();
        for (Product product : list) {
            product.setModifiedUser(null);
            product.setCreatedUser(null);
            product.setModifiedTime(null);
            product.setCreatedTime(null);
            product.setPriority(null);

        }
        return list;
    }

    @Override
    public Product findById(Integer id) {
        Product pro = productMapper.findById(id);
        if (pro==null){
            throw new ProductNotFindException("商品信息未找到或者该商品不存在或者该商品已经下架");
        }
//        将查询结果部分设置为空
        pro.setModifiedUser(null);
        pro.setCreatedUser(null);
        pro.setModifiedTime(null);
        pro.setCreatedTime(null);
        pro.setPriority(null);

        return pro;
    }
}
